﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Text;
using System.IO;
using System.Net.Security;

public partial class Police_TranslateApprove_Defaulttemp : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button2_Click(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ExportData("application/ms-Word", DateTime.Now.ToString("yyMdHm") + ".doc");
    }

    private void ExportData(string FileType, string FileName)
    {
        Response.Charset = "GB2312";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");

        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
        Response.ContentType = FileType;
        this.EnableViewState = false;
        StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        Main.RenderControl(hw);
        Response.Write(tw.ToString());
        Response.End();
    }

    public override void VerifyRenderingInServerForm(Control control)
    {
        //base.VerifyRenderingInServerForm(control);
    }
    protected void BtnPrint_Click(object sender, EventArgs e)
    {
        Uri url = new Uri("http://10.24.10.13/Police/TranslateApprove/Defaulttemp.aspx");
        WebClient client = new WebClient();
        client.Credentials = CredentialCache.DefaultCredentials;
        client.OpenRead(url);
        Stream stream = client.OpenRead(url);
        //WebRequest HR = WebRequest.Create("http://localhost:7570/Web/Police/TranslateApprove/Defaulttemp.aspx");
        //HR.Timeout = 5000;
        //HR.AuthenticationLevel = AuthenticationLevel.MutualAuthRequested;
        //// Supply client credentials.
        //HR.Credentials = CredentialCache.DefaultNetworkCredentials;          
        //WebResponse HRP = HR.GetResponse() as WebResponse;        
        StreamReader reader = new StreamReader(stream, System.Text.Encoding.GetEncoding("GB2312"));
        string TempStr = reader.ReadToEnd();
        int index = TempStr.IndexOf("<div id=ccc>");
        TempStr = TempStr.Substring(0, index);
        TempStr += "<script languge='Javascript'>WebBrowser.ExecWB(7,1); window.opener=null;window.close();</script>";
        TempStr += "</from></body></html>";
        Response.Write(TempStr);
    }
}
